/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newspaper;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 
 * @author xuanhung2401
 */
public class VnexpressImage extends Thread {

	String imageURL = "";
	String imageName = "";
	public static String imagePath = "";

	public VnexpressImage(String imageURL, String imageName) {
		this.imageURL = imageURL;
		this.imageName = imageName;
		this.start();
	}

	@Override
	public void run() {
		InputStream in = null;
		try {
			URL url = new URL(imageURL);
			in = url.openStream();
			
			
			FileOutputStream fileOut = new FileOutputStream(imageName);
			OutputStream out = new BufferedOutputStream(fileOut);
			for (int b; (b = in.read()) != -1;) {
				out.write(b);
			}
			out.close();
			in.close();
		} catch (IOException ex) {
			Logger.getLogger(VnexpressImage.class.getName()).warning(ex.getMessage());
				
		} finally {
			try {
				in.close();
			} catch (IOException ex) {
				Logger.getLogger(VnexpressImage.class.getName()).log(
						Level.SEVERE, null, ex);
			}
		}
	}
}
